<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登陆界面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head>
<body>
              
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>请输入账号和密码进行客服登录</legend>
</fieldset>
 
<form class="layui-form" action="">
    <div class="layui-form-item">
    <label class="layui-form-label">*账号*</label>
    <div class="layui-input-inline">
    <input type="text" name="id" lay-verify="title" autocomplete="off" placeholder="请输入账号" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请填写您的客服账号</div>
    </div>
  
    <div class="layui-form-item">
    <label class="layui-form-label">*密码*</label>
    <div class="layui-input-inline">
    <input type="password" name="password" lay-verify="pass" autocomplete="off" placeholder="请输入密码" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
    </div>
  
    <div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
    </div>
</form>
  
<script src="./layui/layui.js" charset="utf-8"></script>
<script>
layui.use(['form','layer','layedit','jquery'], function(){
    var form = layui.form,
        layer = layui.layer,
        layedit = layui.layedit,
        $= layui.jquery;
    //创建一个编辑器
    var editIndex = layedit.build('LAY_demo_editor');
    
    //自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 5){
                return '账号至少得5个字符啊';
            }
        },
        pass: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ],
        content: function(value){
            layedit.sync(editIndex);
        }
    });

    // 监听提交
    form.on('submit(demo1)', function(data){
        console.log("返回的结果是啥啊",data.field,data.field.id,data.field.password);
        layui.jquery.post("/managerLogin",data.field,function(result){
            if(result.status == "fail"){
                layer.alert(JSON.stringify(result.msg),function(){
                    window.parent.location.reload();    // 刷新父类页面
                    parent.layer.close(index);          // 关闭当前的弹窗
                });
                console.log("返回的结果是啥啊",result);
            }else {
                location.href="/?val=userManager&selfid=" + data.field.id;
                console.log('去超管页面');
            }
        })
        return false;
    });
});
</script>
</body>
</html>